import request from '@/utils/request'
import captchaTypeEnum from '@/enums/captchaTypeEnum'

export function loginByUsername(username, password, captcha) {
  const data = {
    username,
    password,
    captcha
  }
  return request({
    url: '/sapi/sys/login/login',
    method: 'post',
    data: data
  })
}

export function logout() {
  return request({
    url: '/sapi/sys/login/logout',
    method: 'post'
  })
}

export function getUserInfo(token) {
  return request({
    url: '/sapi/sys/user/current/detail',
    method: 'post',
    data: { token }
  })
}

/** *
 * 获取登录验证码
 */
export function getLoginCaptcha() {
  var postData = {}
  postData.type = captchaTypeEnum.LOGIN.value
  postData.time = new Date().getTime()
  postData.skipLoading = true
  return request({
    url: '/sapi/captcha/get',
    method: 'post',
    data: postData
  })
}
